﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BetterIO.Tests
{
    public static class Helper
    {
        public static void ExpectException<T>(Action action)
            where T : Exception
        {
            bool caught = false;
            try
            {
                action();
            }
            catch (T)
            {
                caught = true;
            }
            catch (Exception e)
            {
                Assert.Fail("Expected to catch exception of type: " + typeof(T).Name + ", but caught " + e.GetType().Name);
            }

            Assert.IsTrue(caught, "Expected to catch exception of type: " + typeof(T).Name);
        }

        public static void ForEach<T>(this IEnumerable<T> test, Action<T> testCode)
        {
            foreach (var item in test)
            {
                testCode(item);
            }
        }
    }
}